package com.ruoyi.web.controller.inspection;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.inspection.domain.TPlace;
import com.ruoyi.inspection.service.ITPlaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 巡检地点Controller
 * 
 * @author ruoyi
 * @date 2024-06-04
 */
@RestController
@RequestMapping("/inspection/place")
public class TPlaceController extends BaseController
{
    @Autowired
    private ITPlaceService tPlaceService;

    /**
     * 查询巡检地点列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:place:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPlace tPlace)
    {
        startPage();
        List<TPlace> list = tPlaceService.selectTPlaceList(tPlace);
        return getDataTable(list);
    }

    /**
     * 导出巡检地点列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:place:export')")
    @Log(title = "巡检", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPlace tPlace)
    {
        List<TPlace> list = tPlaceService.selectTPlaceList(tPlace);
        ExcelUtil<TPlace> util = new ExcelUtil<TPlace>(TPlace.class);
        util.exportExcel(response, list, "巡检数据");
    }

    /**
     * 获取巡检地点详细信息
     */
    @PreAuthorize("@ss.hasPermi('inspection:place:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tPlaceService.selectTPlaceById(id));
    }

    /**
     * 新增巡检地点
     */
    @PreAuthorize("@ss.hasPermi('inspection:place:add')")
    @Log(title = "巡检", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPlace tPlace)
    {

        return toAjax(tPlaceService.insertTPlace(tPlace));
    }

    /**
     * 修改巡检地点
     */
    @PreAuthorize("@ss.hasPermi('inspection:place:edit')")
    @Log(title = "巡检", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPlace tPlace)
    {
        return toAjax(tPlaceService.updateTPlace(tPlace));
    }

    /**
     * 删除巡检地点
     */
    @PreAuthorize("@ss.hasPermi('inspection:place:remove')")
    @Log(title = "巡检", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tPlaceService.deleteTPlaceByIds(ids));
    }
}
